package com.smart.parking.controller.backstage;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.smart.parking.config.Result;
import com.smart.parking.entity.PriceEntity;
import com.smart.parking.service.PriceService;
import com.smart.parking.utils.PageUtils;
import com.smart.parking.vo.PriceVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * 停车收费价格表
 *
 * @author ciyun
 */
@RestController
@RequestMapping("/price")
public class PriceController {
    @Autowired
    private PriceService priceService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public Result list(@RequestParam Map<String, Object> params){
        PageUtils page = priceService.queryPage(params);

        return Result.ok().put("page", page);
    }

    /**
     * 添加价格
     *
     * @param priceVO 价格签证官
     * @return {@link Result}
     */
    @PostMapping("/addPrice")
    public Result addPrice(@RequestBody PriceVO priceVO){
        priceService.addPrice(priceVO);
        return Result.ok();
    }

    /**
     * 批量添加价格
     *
     * @param priceVOList 价格volist
     * @return {@link Result}
     */
    @PostMapping("/addPriceList")
    public Result addPriceList(@RequestBody List<PriceVO> priceVOList){
        priceService.addPriceList(priceVOList);
        return Result.ok();
    }

    /**
     * 删除价格
     *
     * @param priceId 价格id
     * @return {@link Result}
     */
    @DeleteMapping("/deletePrice")
    public Result deletePrice(@RequestParam("priceId") Long priceId){
        priceService.deletePrice(priceId);
        return Result.ok();
    }

    /**
     * 批量删除价格
     *
     * @param priceIds 价格id
     * @return {@link Result}
     */
    @DeleteMapping("/deletePrices")
    public Result deletePrices(@RequestBody Long[] priceIds){
        priceService.deletePrices(priceIds);
        return Result.ok();
    }


    /**
     * 更新价格
     *
     * @param priceEntity 价格实体
     * @return {@link Result}
     */
    @PutMapping("/updatePrice")
    public Result updatePrice(@RequestBody PriceEntity priceEntity){
        priceService.updatePrice(priceEntity);
        return Result.ok();
    }

}
